<?php
session_start();
/*if (!isset($_SESSION['level']) || $_SESSION['level'] == ''){
	echo "<script type='text/javascript'>window.location='../index.php';</script>"; 
}
$level = $_SESSION['level'];*/
  // Các giá trị dược lưu trong biến $_POST
  // Kiểm tra nếu được post
  if(isset($_REQUEST['id'])) {
	$id = $_REQUEST['id']; //id ma~ gian hang 
  		include_once('controller/db.php');
		$db = new DB;
		$result = $db->execute("select * from gianhang where MaGianHang = $id ");
		$row=mysql_fetch_array($result);
      // Đưa dữ liệu vào các biến
	    $MaGianHang = $row['MaGianHang'];
		$TenGianHang = $row['TenGianHang'];
		$MaTV = $row['MaTV'];
		$MaSP = $row['MaSP'];
		$NgayDangKy = $row['NgayDangKy'];	
 }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Create 1</title>
    <link rel="stylesheet" type="text/css" href="../css/design.css">
	<script type="text/javascript" src="../css/js/jquery.js"></script>
	<script type="text/javascript" src="../css/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="../css/localization/messages_vi.js"></script>
      <style type="text/css">
        body{margin: 0; padding: 0; font: 13px Arial, Helvetica, sans-serif; background: url(../css/bg.jpg) top center no-repeat fixed; color: #333333;}
      </style>
  </head>
  <body>
    <div class="login_container">
      <div class="login_header">
        <div class="logo"></div>
      </div>
	  </br>
      <div class="admin">
	      <form id="edit_gianhang" class="fedit" action="edit_gianhang.php" method="post">
			<fieldset><legend><h2>SỬA THÔNG TIN GIAN HÀNG</h2></legend>
				<p style="display:none;"><label for="name">Mã gian hàng</label>
				<input type="text" name="id" id="id" value="<?php echo $id ?>"/></p>
			    <p><label for="name">Tên gian hàng</label>
			    <input type="text" name="TenGianHang" id="TenGianHang" class="required" value="<?php echo $TenGianHang ?>" /></p>
				<p><label for="name">Mã thành viên</label>
			    <input type="text" name="MaTV" id="MaTV" class="required" value="<?php echo $MaTV ?>"/></p>
				<p><label for="name">Mã sản phẩm</label>
			    <input type="text" name="MaSP" id="MaSP" class="required" value="<?php echo $MaSP ?>" /></p>
				<p><label for="name">Ngày đăng ký</label>
			    <input type="text" name="NgayDangKy" id="NgayDangKy" class="required" value="<?php echo $NgayDangKy ?>" /></p>
	            <p class="submit"><input name="submit" type="submit" id="submit" value="Đồng ý" /></p>
			</fieldset>
      </div>
    </div>
  </body>
</html>
<?php
    if(isset($_POST["id"]))
    {
		$MaGianHang = $_POST["id"];
        $TenGianHang = $_POST["TenGianHang"];
		$MaTV = $_POST["MaTV"];
		$MaSP = $_POST["MaSP"];
		$NgayDangKy = $_POST["NgayDangKy"];	
        $result2 = $db->execute("update gianhang set TenGianHang = '$TenGianHang', MaTV = '$MaTV', MaSP = '$MaSP', NgayDangKy = '$NgayDangKy' where MaGianHang = $MaGianHang");
		if(!$result2)
			echo "<script type='text/javascript'>alert('>>> ( Failed !!! ) <<<'); window.location='mana_gianhang.php';</script>"; 
		echo "<script type='text/javascript'>window.location='mana_gianhang.php';</script>";
		$db->disConnect();
    }
?>
<script>
$(document).ready(function(){
	// Validate form
	$("#edit_gianhang").validate({
		errorElement: "span", // Định dạng cho thẻ HTML hiện thông báo lỗi
	});
});
</script>